package org.haxenme.inapppurchase;


import nme.display.Sprite;
import nme.display.StageAlign;
import nme.display.StageScaleMode;
import nme.Lib;
import nme.monetize.InAppPurchase;
import nme.monetize.data.InAppPurchaseItem;


/**
 * @author Joshua Granick
 */
class InAppPurchaseTest extends Sprite {
	
	
	public function new () {
		
		super ();
		
		initialize ();
		construct ();
		
	}
	
	
	private function construct ():Void {
		
		InAppPurchase.getAvailableItems (InAppPurchase_onGetAvailableItems);
		
	}
	
	
	private function initialize ():Void {
		
		Lib.current.stage.align = StageAlign.TOP_LEFT;
		Lib.current.stage.scaleMode = StageScaleMode.NO_SCALE;
		
	}
	
	
	
	
	// Event Handlers
	
	
	
	
	private function InAppPurchase_onGetAvailableItems (items:Array <InAppPurchaseItem>):Void {
		
		var item = items[0];
		
		trace ("Item ID is " + item.itemID);
		
		InAppPurchase.getItemDetails (item.itemID, InAppPurchase_onGetItemDetails);
		
	}
	
	
	private function InAppPurchase_onGetItemDetails (item:InAppPurchaseItem) {
		
		trace ("Got item details");
		trace (item);
		
	}
	
	
	
	
	// Entry point
	
	
	
	
	public static function main () {
		
		Lib.current.addChild (new InAppPurchaseTest ());
		
	}
	
	
}